package com.srit.map.web.action;

import java.io.PrintWriter;
import java.util.List;

import org.apache.struts2.json.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;

import com.srit.core.struts2.action.CrudAction;
import com.srit.map.business.bean.Company;
import com.srit.map.business.bean.CompanyDescription;
import com.srit.map.business.bean.CompanySearch;
import com.srit.map.business.bean.SearchBean;
import com.srit.map.business.service.MapService;

/**
 * @author chenxiling
 * 前端查询
 *
 */
public class MapSearchAction extends CrudAction{
	
	private Company company=new Company();
	@Autowired(required = true)
	MapService mapService;

	@Override
	public Object getModel() {
		// TODO Auto-generated method stub
		return company;
	}
	//地图展示后台部分，前台也可用转跳部分
	public String page(){
		return "jump";
	}
	
	//10.26公司名称查询地图展示
	public String searchInMap(){
		String name=company.getName();
		List list=mapService.searchMapbyName(company);
		page.setList(list);
		request.setAttribute("page", page);
		return "success";
	}
	
	//10.31查询栏的点击查询
	public String search(){
		String fund_min=request.getParameter("fund_min");
		String fund_max=request.getParameter("fund_max");
		String company_property=request.getParameter("company_property");
		CompanySearch companySearch=new CompanySearch();
		if(fund_min!=null&&fund_max!=null){
			companySearch.setFund_min(fund_min);
			companySearch.setFund_max(fund_max);
		}
		if(company_property!=null){
			companySearch.setCompany_property(company_property);
		}
		List list=mapService.searchCompany(companySearch);
		page.setList(list);
		request.setAttribute("page", page);
		return "input";
	}
	
	public String searchByKey(){
		String searchKey = request.getParameter("searchKey");
		SearchBean searchBean = new SearchBean();
		searchBean.setSearchKey(searchKey);
		if(searchBean != null){
			page.setSp(searchBean);
		}
		page.setPageSize(10);
		mapService.searchCompanyByKey(page);
//		response.setContentType("application/json;charset=UTF-8");
//		PrintWriter out;
//		try {
//			String str=JSONUtil.serialize(list);
//			out = response.getWriter();
//			out.println(str);
//			out.flush();
//			out.close();
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		return "jump";
	}
}